package com.smart.campus.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.campus.dao.SecurityGuardMapper;
import com.smart.campus.dto.SecurityGuard;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.service.SecurityGuardService;
import com.smart.campus.util.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @BelongsProject: smart-campus
 * @BelongsPackage: com.smart.campus.service.impl
 * @Author: Y S Z
 * @CreateTime: 2024-10-07  11:49
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class SecurityGuardServiceImpl implements SecurityGuardService {
    @Autowired
    private SecurityGuardMapper securityGuardMapper;

    @Override
    public List<SecurityGuard> findSecurityGuardList() {
        return securityGuardMapper.selectList(null);
    }

    @Override
    public PagedResponse<SecurityGuard> pageSecurityGuard(SecurityGuard securityGuard, Integer pageNum, Integer pageSize) {
        Page<SecurityGuard> page = new Page<>(pageNum, pageSize);
        IPage<SecurityGuard> securityGuardIPage = securityGuardMapper.pageSecurityGuard(securityGuard, page);
        return PaginationUtil.getPaginationResponse(securityGuardIPage.getRecords(),pageNum,pageSize,securityGuardIPage.getTotal());
    }

    @Override
    public void addSecurityGuard(SecurityGuard securityGuard) {
        securityGuard.setSgAge(40);
        securityGuard.setSgHireQuality(1);
        securityGuard.setCreateTime(new Date());
        securityGuard.setUpdateTime(new Date());
        securityGuardMapper.insert(securityGuard);
    }

    @Override
    public void delSecurityGuard(Long id) {
        securityGuardMapper.deleteById(id);
    }

    @Override
    public SecurityGuard findSecurityGuardById(Long id) {
        return securityGuardMapper.selectById(id);
    }

    @Override
    public void updSecurityGuard(SecurityGuard securityGuard) {
        securityGuardMapper.updateById(securityGuard);
    }
}
